var Light = (function () {
    var lightState = function () {

        },
        offLight = function (light) {
            this.light = light;
        },
        weakLight = function (light) {
            this.light = light;
        },
        normalLight = function (light) {
            this.light = light;
        },
        heightLight = function (light) {
            this.light = light;
        },
        lightFun = function () {
            this.offLightState = new offLight(this);
            this.weakLightState = new weakLight(this);
            this.normalLightState = new normalLight(this);
            this.heightLightState = new heightLight(this);
            this.currState = this.offLightState;
        };
    offLight.prototype.buttonWasPressed = function () {
        alert('柔光');
        this.light.setState(this.light.weakLightState);
    };
    weakLight.prototype.buttonWasPressed = function () {
        alert('常光');
        this.light.setState(this.light.normalLightState);
    };
    normalLight.prototype.buttonWasPressed = function () {
        alert('高亮');
        this.light.setState(this.light.heightLightState);
    };
    heightLight.prototype.buttonWasPressed = function () {
        alert('关闭');
        this.light.setState(this.light.offLightState);
    };
    lightFun.prototype.init = function () {
        this.create();
        this.initEvent();
    };
    lightFun.prototype.create = function () {
        var button = document.createElement('button');
        button.innerHTML = '开关';
        this.button = document.body.appendChild(button);
    };
    lightFun.prototype.setState = function (newState) {
        this.currState = newState;
    };
    lightFun.prototype.initEvent = function () {
        var self = this;
        this.button.addEventListener('click', function () {
            self.currState.buttonWasPressed();
        })
    };
    return lightFun;
})();
$(function () {
    new Light().init();
});